package com.atguigu.test;

import org.junit.Test;

public class JUnitPro {

    /**
     * 用来理解getClass()
     * new子类时候，在父类中getClass()是子类
     */
    @Test
    public void test01(){
       // Person person = new Person();
        Person son = new Son();
        son.init();

        Person p1 = new Person();
        p1.init();

        //子类对象被父类引用可以
        Person ps = new Son();
        ps.init();

        //父类对象强转子类不行
        Son sp = (Son) new Person();
        sp.init();
    }
}


class Person{
    public Person() {
        String name = this.getClass().getName();
        System.out.println("person name:"+name);
    }

    public void init(){
        System.out.println("ppppp");
    }
}


class Son extends Person{
    public Son() {
        String name = getClass().getName();
        System.out.println("son name:"+name);
    }

    @Override
    public void init() {
        System.out.println("ssssss");
    }
}